package cn.tedu.restaurant.controller;

import cn.tedu.restaurant.common.JsonResult;
import cn.tedu.restaurant.entity.Dishes;
import cn.tedu.restaurant.entity.Order;
import cn.tedu.restaurant.service.OrderService;
import cn.tedu.restaurant.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-05
 */
@RestController @RequestMapping("/order") public class OrderController {

    @Autowired @Resource private OrderService orderService;

    private static final Integer SUCCESS = 200;

    @RequestMapping("insert")
    public JsonResult<Void> insertOrder1(HttpSession session,@RequestParam("orderTime") String time, @RequestParam("orderSeat") Integer orderSeat,@RequestParam("orderAttendance") Integer orderNum,
       @RequestParam("remark") String text,@RequestParam("id") Integer id) {
        JsonResult<Void> result = new JsonResult<Void>(SUCCESS);
        Integer uid = Integer.valueOf(session.getAttribute("uid").toString());
        String username1 = session.getAttribute("username").toString();
        String phone1 = session.getAttribute("phone").toString();
        orderService.insertOrder(uid,id,time, orderSeat, orderNum, phone1, username1, text);
        return result;
    }

    @RequestMapping("list")
    public JsonResult<List<Order>> listOrders(HttpSession session) {
        JsonResult<List<Order>> result = new JsonResult<List<Order>>(SUCCESS);
        Integer uid = Integer.valueOf(session.getAttribute("uid").toString());
        orderService.getOrders(uid);
        return result;
    }
    @RequestMapping("count")
    public JsonResult<Integer> OrderCount(HttpSession session) {
        JsonResult<Integer> result = new JsonResult<Integer>(SUCCESS);
        Integer uid = Integer.valueOf(session.getAttribute("uid").toString());
        result.setData(orderService.getCount());
        return result;
    }

    @RequestMapping("listNoOrder")
    public JsonResult<List<OrderVo>> Order(HttpSession session) {
        JsonResult<List<OrderVo>> result = new JsonResult<List<OrderVo>>(SUCCESS);
        Integer uid = Integer.valueOf(session.getAttribute("uid").toString());
        result.setData(orderService.getUserOrders(uid));
        return result;
    }
}
